package servlet;


import dao.AdministratorDao;
import dao.UserDao;
import dao.daoimpl.AdministratorImpl;
import dao.daoimpl.UserDaoImpl;
import bean.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;


@WebServlet(name="StartUpServlet",urlPatterns = "/StartUpServlet")
public class StartUpServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");/*防止乱码*/
        String start=request.getParameter("start");
        AdministratorDao administratorDao=new AdministratorImpl();
        UserDao userDao=new UserDaoImpl();
        try {
            request.getSession().setAttribute("allCommands",administratorDao.getAllCommand());
            request.getSession().setAttribute("allArticles",administratorDao.getAllArticles());
            request.getSession().setAttribute("allUsers",userDao.getAllUsers());
            request.getSession().setAttribute("user",new User());
            response.sendRedirect(start);
        } catch (SQLException sqlException) {
            sqlException.printStackTrace();
        }
    }
}
